//
//  HZL_FourthTableViewCell.m
//  B_Project
//
//  Created by 刘峻豪 on 15/11/25.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_FourthTableViewCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"

@interface HZL_FourthTableViewCell ()
@property (nonatomic, strong) UIImageView *photoView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *category;

@end
@implementation HZL_FourthTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.photoView = [[UIImageView alloc]init];
    self.photoView.contentMode = UIViewContentModeScaleAspectFill;
    self.photoView.clipsToBounds = YES;
    [self.contentView addSubview:self.photoView];
    
//    self.backView = [[UIView alloc]init];
//    self.backView.alpha = 0.3;
//    [self.contentView addSubview:self.backView];
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.titleLabel];
    
    self.category = [[UILabel alloc]init];
    self.category.textColor = [UIColor whiteColor];
    self.category.font = [UIFont systemFontOfSize:14];
    self.category.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.category];
    
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.photoView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.titleLabel.frame = CGRectMake(0, self.contentView.frame.size.height / 2 - 10, self.contentView.frame.size.width, 30);
    self.category.frame = CGRectMake(0, self.contentView.frame.size.height / 2 +20, self.contentView.frame.size.width, 25);
    
//    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(260, 50));
//        make.top.mas_equalTo(self.contentView.mas_top).offset((self.contentView.frame.size.height - 50) / 2);
//        make.left.mas_equalTo(self.contentView.mas_left).offset((self.contentView.frame.size.width - 260) / 2);
//    }];
    
    
//    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width, 50));
//        make.top.mas_equalTo(self.contentView.mas_top).offset((self.contentView.frame.size.height - 50) / 2);
//    }];
//    self.backView.backgroundColor = [UIColor blackColor];

}
- (void)setModel:(HZL_FourthViewModel *)model
{
    if (_model != model) {
        _model = model;
    }
    self.titleLabel.text = model.title;
    [self.photoView sd_setImageWithURL:[NSURL URLWithString:model.coverForFeed]];
    
    NSNumber *minute = [NSNumber numberWithInt:[model.duration intValue] / 60];
    NSNumber *second = [NSNumber numberWithInt:[model.duration intValue] % 60];
    NSString *time = [NSString stringWithFormat:@" %@' %@'' ", minute, second];
    self.category.text = [NSString stringWithFormat:@"#%@ / %@ ", model.category, time];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
